package homework;
//作业标题(2309)
//判断链表带环
//
//作业内容
//判断链表带环
//https://leetcode.cn/problems/linked-list-cycle/description/
public class h2309 {
      class ListNode {
      int val;
      ListNode next;
      ListNode(int x) {
          val = x;
          next = null;
      }
  }
    public boolean hasCycle(ListNode head) {
        if(head == null || head.next == null) return false;

        ListNode fast = head;
        ListNode last = head;
        while(fast != null && fast.next != null)
        {
            fast = fast.next.next;
            last = last.next;
            if(fast == last)
            {
                return true;
            }
        }
        return false;
    }
}
